# encoding: utf-8

from fastapi import APIRouter
from fastui import AnyComponent, FastUI
from fastui import components
from fastui.events import GoToEvent, PageEvent
from typing import Literal, TypeAlias


router = APIRouter()


gametype: TypeAlias = Literal['YYS', 'YYJH']
@router.get('/{kind}', response_model=FastUI, response_model_exclude_none=True)
def page_reminder_default(kind: gametype) -> list[AnyComponent]:
    return reminder_modelpage(
        components.LinkList(
            links=[
                components.Link(
                    components=[components.Text(text='阴阳师')],
                    on_click=PageEvent(name='tab', push_path='/reminder/YYS', context={'kind': 'YYS'}),
                    active='/reminder/YYS',
                ),
                components.Link(
                    components=[components.Text(text='烟雨江湖')],
                    on_click=PageEvent(name='tab', push_path='/reminder/YYJH', context={'kind': 'YYJH'}),
                    active='/reminder/YYJH',
                ),
            ],
            mode='tabs',
        ),
        components.ServerLoad(
            path='/reminder/{kind}/loading',
            load_trigger=PageEvent(name='tab'),
            components=reminder_loading(kind),
        ),
    )


@router.get('/{kind}/loading', response_model=FastUI, response_model_exclude_none=True)
def reminder_loading(kind: gametype) -> list[AnyComponent]:
    return [
        components.Text(text=kind),
    ]


@router.get('/{path:path}', status_code=404)
async def api_404():
    return {'message': 'Not Found'}


# 日常模块模板
def reminder_modelpage(*coms: AnyComponent) -> list[AnyComponent]:
    return [
        components.Navbar(
            title='日常',
            title_event=GoToEvent(url='/reminder'),
            start_links=[
                components.Link(
                    components=[components.Text(text='首页')],
                    on_click=GoToEvent(url='/'),
                    active='startswith:/',
                ),
            ],
        ),
        components.Page(
            components=[
                *coms,
            ],
        ),
        components.Footer(
            extra_text='Design by LinHW',
            links=[
                components.Link(
                    components=[components.Text(text='gitee address')], on_click=GoToEvent(url='https://gitee.com/LinHW2000/gamewebtools')
                ),
            ],
        ),
    ]

